package com.most.auth.controller;

import com.most.redis.RedisUtil;
import com.most.auth.service.LoginService;
import com.most.util.JwtUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping
@RefreshScope
@Api("登陆模块")
public class LoginController {


    @Autowired
    LoginService loginService;
    @Autowired
    RedisUtil redisUtil;

    @GetMapping("/login")
    @ResponseBody
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password) {
        return loginService.login(username, password);
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        String username = JwtUtils.getUserName(token);
        redisUtil.del(username);
        return "";
    }
    @GetMapping("/asd")
    public String asd(HttpServletRequest request) {

        return "asd";
    }


}